package top.leyi.mapper;


import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import top.leyi.entity.SQLUtil;
import top.leyi.entity.data.Data;
import top.leyi.entity.data.Type;

import java.util.List;

public interface DataMappper {

     @Select("SELECT d.name,d.secret, d.id,d.details,d.url,  dt.name as type,u.username, u.headPic,u.id as userId " +
             "FROM data d join user u " +
             "on u.id = d.user_id " +
             "join data_type dt " +
             "on dt.id = d.type "+
             "and d.name like '%${key}%' " +
             "ORDER BY d.id DESC " +
             "LIMIT #{limit} OFFSET #{offset} ")
    public List<Data> fuzzyQueryData(SQLUtil sqlUtil);


   @Select("SELECT d.name,d.id,d.details,d.url,  dt.name as type,u.username, u.headPic,u.id as userId " +
            "FROM data d join user u " +
            "on u.id = d.user_id " +
            "join data_type dt " +
            "on dt.id = d.type "+
            "where is_delete = 0 " +
            "and d.type =  #{type} " +
            "and d.name like '%${key}%' " +
            "ORDER BY d.id DESC " +
            "LIMIT #{limit} OFFSET #{offset} ")
    public List<Data>  queryDataWithType(SQLUtil sqlUtil );

     @Select("SELECT * FROM data_type")
     public List<Type> getAllType( );


    @Insert("INSERT INTO data(  name, details, url, type, user_id ) VALUES " +
             "(#{name},#{details},#{url},#{type},#{userId} )")
     public void addData(Data data);


    @Delete("UPDATE data SET is_delete = 1 WHERE id = #{id}")
    public void removeData(int id);
}
